<template>
	<div>
		<div>
			<el-input
				style="width: 300px; margin-right: 10px; margin-left: -500px;"
				clearable
				@clear="initPlan"
				v-model="diseaseCause"
				@keydown.enter.native="initPlan"
			    placeholder="请输入病因进行搜索"
			    prefix-icon="el-icon-search">
			</el-input>
			<el-button type="primary" @click="initPlan">搜索</el-button>
			<el-button type="primary" @click="showPlanAdd">添加</el-button>
		</div>
		<div>
			<el-table
			    :data="planData"
			    stripe
				border
			    style="width: 100%">
			    <el-table-column
			      prop="patientId"
			      label="病人号"
			      width="100"
				  >
			    </el-table-column>
			    <el-table-column
			      prop="diseaseCause"
			      label="病因"
			      width="100">
			    </el-table-column>
			    <el-table-column
			      prop="prescription"
			      label="治疗处方"
				  width="150">
			    </el-table-column>
				<el-table-column
				  prop="physician"
				  label="主治医生"
				  width="100">
				</el-table-column>
				<el-table-column
				  prop="therapist"
				  label="治疗医师"
				  width="100">
				</el-table-column>
				<el-table-column
				  prop="starttime"
				  label="开始时间"
				  width="100">
				</el-table-column>
				<el-table-column
				  prop="recoveryCycle"
				  label="治疗周期"
				  width="100">
				</el-table-column>
				<el-table-column
				  label="操作"
				  align="center"
				  width="200">
				  <template slot-scope="scope">
					  <el-button @click="showPlanEdit(scope.row)">编辑</el-button>
					  <el-button @click="deletePlan(scope.row)" type="danger">删除</el-button>
				  </template>
				</el-table-column>
			  </el-table>
			  <el-pagination
			    background
				@current-change="currentChange"
			    layout="prev, pager, next,jumper,->,total"
			    :total=total>
			  </el-pagination>
		</div>
		 <el-dialog title="康复计划添加" :visible.sync="dialogVisible">
		 	<PlanAdd  :dialogVisible.sync=dialogVisible @add="initPlan()"></PlanAdd>
		 </el-dialog>
		
		<el-dialog title="康复计划编辑" :visible.sync="editVisible">
			<PlanEdit :editVisible.sync="editVisible" :formData="formData"></PlanEdit>
		</el-dialog>
	</div> 
</template>

<script>
	import PlanAdd from './plan_add.vue'
	import PlanEdit from './plan_edit.vue'
	
	export default{
		name:"RecoveryPlan",
		components:{
			PlanAdd,
			PlanEdit
		},
		data(){
			return{
				planData:[],
				total:0,
				currentPage:1,
				size:10,
				diseaseCause:'',
				dialogVisible:false,
				editVisible:false,
				formData:{
					patientId:'',
					diseaseCause:'',
					prescription:'',
					physician:'',
					therapist:'',
					starttime:'',
					recoveryCycle:''
				}
			}
		},
		mounted(){
			this.initPlan();
		},
		methods:{
			showPlanEdit(data){
				this.editVisible=true;
				this.formData=data;
				// console.log("父组件数据:");
				// console.log(this.formData)
			},
			deletePlan(data){
				this.$confirm('此操作将永久删除'+data.patientId+'号病人的康复计划，是否继续？','提示',{
					confirmButtonText:'确定',
					cancelButtonText:'取消',
					type:'warning'
				}).then(() => {
					this.getRequest('/recovery/delete?patientId='+data.patientId).then(resp =>{
						if(resp){
							this.initPlan();
						}
					})
				}).catch(() => {
					this.$message({
						type:'info',
						message:'已取消删除'
					});
				});
			},
			currentChange(currentPage){
				this.currentPage=currentPage;
				this.initPlan();
			},
			showPlanAdd(){
				this.dialogVisible=true
			},
			initPlan(){
				this.getRequest('/recovery/planList?currentPage='+this.currentPage+'&size='+this.size+'&diseaseCause='+this.diseaseCause).then(resp=>{
					if(resp){
						this.planData=resp.data;
						this.total=resp.total;
					}
				})
			}
		}
	}
</script>

<style>
</style>
